package com.jubotech.business.web.interceptor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;

@Configuration
public class WebConfiguration extends WebMvcConfigurationSupport {
    @Bean
    public ViewResolver viewResolver() {
        FreeMarkerViewResolver resolver = new FreeMarkerViewResolver();
        //resolver.setCache(true);
        resolver.setPrefix("");
        resolver.setSuffix(".ftl");
        resolver.setContentType("text/html; charset=UTF-8");
        return resolver;
    }

    @Bean
    public FreeMarkerConfigurer freeMarkerConfigurer() {
        FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
        configurer.setTemplateLoaderPaths("classpath:/templates/");
        configurer.setDefaultEncoding("UTF-8");
        //configurer.setFreemarkerVariables();
        return configurer;
    }

 
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		System.out.println("进入拦截器。。。。");
//		InterceptorRegistration ir =  registry.addInterceptor(new ExceptionInterceptor());
//		ir.addPathPatterns("/**");
//		ir.excludePathPatterns("/","/cms/**");
		
		registry.addInterceptor(new ExceptionInterceptor()).addPathPatterns("/admin/**","/user/**")
                .excludePathPatterns("/","/user/login","/user/register")
                .excludePathPatterns("/tbk/**");
	    super.addInterceptors(registry);
	}
	



    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
    	 registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
    	 registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
         super.addResourceHandlers(registry);
    }
    
	
}
